package structure;

import hash.Hasher;

import java.util.ArrayList;

import utils.Param;

public abstract class Board {
	
	final protected byte[] config;
	private long hash;
	
	public abstract float[] score();
	public abstract boolean isOver();
	protected abstract void move(Move move);
	public abstract ArrayList<Move> getValidMoves(byte color);
	public abstract boolean isValid(Move move);
	public abstract Board clone();
	public abstract String toString();
	
	public Board(int size){
		this.config = new byte[size*size];
		hash = 0;
	}
	
	public Board(byte[] config, long hash){
		this.config = config;
		this.hash = hash;
	}
	
	
	public Board doMove(Move move){
		Board board = this.clone();
		board.move(move);
		board.setHash(Hasher.getInstance().hash(this, move));
		return board;
	}

	private void setHash(long hash) {
		this.hash = hash;
	}
	
	public byte[] getConfig() {
		return config;
	}
	
	public byte colorAt(Coordinate c){
		return config[Param.SIZE*c.y + c.x];
	}

	public long getHash() {
		return hash;
	}
	
	
}
